#include "PointLight.h"

int PointLight::count = 0;

PointLight::PointLight(glm::vec3 position, glm::vec3 color, 
	glm::vec3 amb, glm::vec3 diff, glm::vec3 spec, 
	float constant, float linear, float quadratic)
	:Light(position, color, amb, diff, spec), m_Constant(constant), m_Linear(linear), m_Quadratic(quadratic)
{
	m_Name = "PointLight" + std::to_string(count++);
	m_ColorName = m_Name + "_Color";
}

PointLight::~PointLight()
{

}
float PointLight::GetConstant() const
{
	return m_Constant;
}

float PointLight::GetLinear() const
{
	return m_Linear;
}

float PointLight::GetQuadratic() const
{
	return m_Quadratic;
}

glm::vec3 PointLight::GetAmbient() const
{
	return m_Color * 0.1f;
}

glm::vec3 PointLight::GetDiffuse() const
{
	return m_Color;
}

glm::vec3 PointLight::GetSpecular() const
{
	return m_Color;
}

void PointLight::Draw(Shader* shader, Camera* camera)
{
	if (shader == nullptr || camera == nullptr) return;

	glm::mat4 model(1.0);
	glm::mat4 view(1.0);
	glm::mat4 projection(1.0);


	
	ImGui::DragFloat3(m_Name.c_str(), glm::value_ptr(m_Position), 0.02f, -500.0f, 500.0f);
	ImGui::ColorEdit3(m_ColorName.c_str(), glm::value_ptr(m_Color));

	model = glm::scale(model, glm::vec3(0.5, 0.5, 0.5));
	model = glm::translate(model, m_Position);
	view = camera->GetViewMatrix();
	projection = camera->GetProjectionMatrix();

	shader->Use();

	shader->SetUniform4Matrix("model", model);
	shader->SetUniform4Matrix("view", view);
	shader->SetUniform4Matrix("projection", projection);
	shader->SetUniform3Float("color", m_Color);

	glBindVertexArray(m_Vao);
	glBindBuffer(GL_ARRAY_BUFFER, m_Vbo);

	glDrawArrays(GL_TRIANGLES, 0, 36);

	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	shader->End();
}




